<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:jsf="http://xmlns.jcp.org/jsf">
    <h:head>
    </h:head>

    <h:body>
        <ui:composition template="/dataverse_template.xhtml">
            <ui:param name="pageTitle" value="#{bundle['pageTitle.passwdReset.pre']} - #{dataverseServiceBean.findRootDataverse().name}"/>
            <ui:param name="dataverse" value="#{dataverseServiceBean.findRootDataverse()}"/>
            <ui:param name="showDataverseHeader" value="false"/>
            <ui:param name="loginRedirectPage" value="dataverse.xhtml"/>

            <ui:define name="metadata">
                <f:metadata>
                    <f:viewParam name="token" value="#{PasswordResetPage.token}"/>
                    <f:viewAction action="#{dataverseSession.updateLocaleInViewRoot}"/>
                    <f:viewAction action="#{PasswordResetPage.init}" />
                </f:metadata>
            </ui:define>
            <ui:define name="body">
                <ui:fragment id="debugVariables" rendered="false">
                    <div style="background-color: lightgray; margin-top:3em;">
                        <tt>
                            <h:outputText value="#{bundle['passwdReset.token']} #{PasswordResetPage.token}"/><br/>
                            <h:outputText value="#{bundle['passwdReset.userLookedUp']} #{PasswordResetPage.user.userName}"/><br/>
                            <h:outputText value="#{bundle['passwdReset.emailSubmitted']} #{PasswordResetPage.emailAddress}"/><br/>
                        </tt>
                    </div>
                </ui:fragment>
                <h1>#{pageTitle}</h1>
                <ui:fragment rendered="#{empty PasswordResetPage.token}">
                    <div jsf:rendered="#{empty PasswordResetPage.emailAddress}">
                        <div class="alert alert-info">
                            <span class="glyphicon glyphicon-info-sign"></span>
                            <h:outputFormat value="#{bundle['passwdReset.details']}" escape="false"> 
                                <f:param value="&lt;strong&gt;"/>
                                <f:param value="&lt;/strong&gt;"/>
                            </h:outputFormat>
                        </div>
                        <h:form id="passwordReset" styleClass="form-horizontal">
                            <p:focus context="passwordReset"/>
                            <div class="form-group col-sm-11">
                                <p:outputLabel value="#{bundle.email}" for="email" styleClass="col-sm-3 control-label"/>
                                <div class="col-sm-4">
                                    <p:inputText id="email" value="#{PasswordResetPage.emailAddress}" styleClass="form-control"/>
                                    <p:watermark for="email" value="me@example.com"/>
                                    <p:focus context="passwordReset"/>
                                    <p:message for="email" display="text" />
                                </div>
                            </div>
                            <div class="form-group col-sm-11">
                                <div class="col-sm-offset-3 col-sm-9 button-block">
                                    <p:commandButton styleClass="btn btn-default" action="#{PasswordResetPage.sendPasswordResetLink()}" update="passwordReset,:messagePanel" value="#{bundle['passwdReset.submitRequest']}"/>
                                    <p:button styleClass="btn btn-link" value="#{bundle.cancel}" outcome="/loginpage.xhtml"/>
                                </div>
                            </div>
                        </h:form>
                    </div>
                    <ui:fragment rendered="#{not empty PasswordResetPage.emailAddress}">
                        <h:outputFormat value="#{bundle['passwdReset.successSubmit.tip']}">
                            <f:param value="#{PasswordResetPage.emailAddress}"/>
                        </h:outputFormat>
                        <ui:fragment id="debugEmail" rendered="false">
                            <div style="background-color: lightgray">
                                <tt>
                                    <h:outputText value="#{bundle['passwdReset.debug']}"/><br/>
                                    <ui:fragment rendered="#{not empty PasswordResetPage.passwordResetUrl}">
                                        <h:outputText value="#{bundle['passwdReset.resetUrl']} "/>
                                        <h:outputLink value="#{PasswordResetPage.passwordResetUrl}">
                                            <h:outputText value="#{PasswordResetPage.passwordResetUrl}"/>
                                        </h:outputLink>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{empty PasswordResetPage.passwordResetUrl}">
                                        <h:outputFormat value="#{bundle['passwdReset.noEmail.tip']}">
                                            <f:param value="#{PasswordResetPage.emailAddress}"/>
                                        </h:outputFormat>
                                    </ui:fragment>
                                </tt>
                            </div>
                        </ui:fragment>
                    </ui:fragment>
                </ui:fragment>
                
                <ui:fragment rendered="#{not empty PasswordResetPage.token}">
                    <h:outputFormat value="#{bundle['passwdReset.illegalLink.tip']}" escape="false" rendered="#{empty PasswordResetPage.user}"> 
                        <f:param value="&lt;a href='/passwordreset.xhtml'&gt;"/>
                        <f:param value="&lt;/a&gt;"/>
                    </h:outputFormat>
                    <ui:fragment rendered="#{not empty PasswordResetPage.user}">
                        <div class="alert alert-info">
                            <span class="glyphicon glyphicon-info-sign"></span>
                            <h:outputFormat value="#{PasswordResetPage.customPasswordResetAlertMessage}" escape="false">
                                <f:param value="&lt;strong&gt;"/>
                                <f:param value="&lt;/strong&gt;"/>
                            </h:outputFormat>
                        </div>
                        <div class="row" jsf:rendered="#{PasswordResetPage.isAccountUpgrade()}">
                            <div class="col-sm-12">
                                <h:outputFormat styleClass="h2 text-info show" value="#{bundle['user.updatePassword.welcome']}">
                                    <f:param value="#{systemConfig.getVersion(true)}"/>
                                </h:outputFormat>
                                <p class="help-block"><span class="text-danger"><span class="glyphicon glyphicon-warning-sign"/> #{bundle['user.updatePassword.warning']}</span></p>
                            </div>
                        </div>
                        <div>
                            <h:form id="passwordResetForm" styleClass="form-horizontal">
                                <p:focus context="passwordResetForm"/>
                                <div class="form-group col-sm-11" jsf:rendered="#{PasswordResetPage.failedValidation}">
                                    <label for="inputPassword" class="col-sm-3 control-label">
                                        #{bundle['passwdReset.newPasswd']} <span class="glyphicon glyphicon-asterisk text-danger" title="#{bundle.requiredField}"></span>
                                    </label>
                                    <div class="col-sm-9" rendered="#{PasswordResetPage.isAccountUpgrade() || PasswordResetPage.isPasswordCompliant()}">
                                        <div class="help-block">
                                            <h:outputFormat value="#{bundle['user.updatePassword.password']}" escape="false">
                                                <f:param value="#{PasswordResetPage.passwordRequirements}"/>
                                            </h:outputFormat>
                                        </div>
                                    </div>
                                    <div class="col-sm-4 col-sm-offset-3">
                                        <p:password id="inputPassword" label="#{bundle.passwd}" match="retypePassword" styleClass="form-control" value="#{PasswordResetPage.newPassword}" validator="#{PasswordResetPage.validateNewPassword}" autocomplete="off"/><!-- browsers will in general not respect autocomplete="foo", but scanners will still flag it as a potential problem -->
					<p:message for="inputPassword"/>
                                    </div>
                                </div>
                                <div class="form-group col-sm-11" jsf:rendered="#{PasswordResetPage.failedValidation}">
                                    <label for="retypePassword" class="col-sm-3 control-label">
                                        #{bundle['passwdReset.rePasswd']} <span class="glyphicon glyphicon-asterisk text-danger" title="#{bundle.requiredField}"></span>
                                    </label>
                                    <div class="col-sm-4">
                                        <p:password id="retypePassword" label="#{bundle['passwdReset.rePasswd']}" styleClass="form-control" value="#{PasswordResetPage.newPassword}" autocomplete="off"/><!-- browsers will in general not respect autocomplete="foo", but scanners will still flag it as a potential problem -->
                                        <p:message for="retypePassword"/>
                                    </div>
                                </div>
                                <ui:fragment rendered="#{PasswordResetPage.isAccountUpgrade()}">
                                    <!-- Terms of Use -->
                                    <ui:include src="termsofuse.xhtml"/>
                                </ui:fragment>
                                <div class="form-group col-sm-11">
                                    <div class="col-sm-10 button-block">
                                        <p:commandButton styleClass="btn btn-default" action="#{PasswordResetPage.resetPassword()}" update="passwordResetForm,:messagePanel" value="#{bundle['passwdReset.resetBtn']}"/>
                                    </div>
                                </div>
                            </h:form>
                        </div>
                    </ui:fragment>
                </ui:fragment>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
